<?php
//生成验证码
class CREATE_CAPTCHA{
	private $width;		//宽
	private $height;		//高
	private $pin_value;		//验证码值
	//构造函数
	public function __construct($width,$height){
		$this->width=$width;
		$this->height=$height;
	}
	//生成验证码背景
	public function create_pin_bg($red,$green,$blue,$x,$y){
		// $width=$this->width;
		// $height=$this->height;
		$image=imagecreatetruecolor($this->width, $this->height);
		$bgcolor=imagecolorallocate($image, $red, $green, $blue);
		imagefill($image, $x, $y, $bgcolor);
		return $image;
	}	
	//生成数字验证码
	public function create_num_pin($image,$number,$fontsize,$red,$green,$blue,$y1,$y2){
		for($i=0;$i<4;$i++){
			$fontcolor=imagecolorallocate($image, $red, $green, $blue);
			$fontcotent=rand(0,9);
			$this->pin_value.=$fontcotent;
			$x=($i*$this->width/$number)+rand($y1,$y2);
			$y=rand($y1,$y2);

			imagestring($image, $fontsize, $x, $y, $fontcotent, $fontcolor);

		}
	} 
	//生成字母数字混合验证码
	public function create_alphanum_pin($image,$number,$fontsize,$red,$green,$blue,$y1,$y2){
		for($i=0;$i<4;$i++){
			$fontcolor=imagecolorallocate($image, $red, $green, $blue);
			$data="abcdefghijkmnpqrstuvwxyz23456789QWERTYUIPASDFGHJKZXCVBNML";
			$fontcotent=substr($data, rand(0,strlen($data)),1);
			$this->pin_value.=$fontcotent;
			$x=($i*$this->width/$number)+rand($y1,$y2);
			$y=rand($y1,$y2);

			imagestring($image, $fontsize, $x, $y, $fontcotent, $fontcolor);

		}
	}
	//获取验证码的值
	public function get_pin_value(){
		return $this->pin_value;
	}
	//生成干扰小圆点
	public function create_interfere_dot($image,$number,$red,$green,$blue){
		for ($i=0; $i <$number ; $i++) { 
			$pointcolor=imagecolorallocate($image,$red,$green,$blue);
			imagesetpixel($image,rand(1,$this->width-1), rand(1,$this->height-1), $pointcolor);
		}

	}
	//产生干扰线
	public function create_interfere_line($image,$number,$red,$green,$blue){
		for ($i=0; $i < $number; $i++) { 
			$linecolor=imagecolorallocate($image,$red,$green,$blue);
			imageline($image, rand(1,$this->width-1), rand(1,$this->height-1), rand(1,$this->width-1), rand(1,$this->height-1), $linecolor);
		}
	}
	//显示验证码图片
	public function show_pin_img($image){
		header("content-type:image/png");
		imagepng($image);
		imagedestroy($image);
	}	
}// end CREATE_CAPTCHA class

//登录验证
class LOGIN_INFO{
	//连接数据库
	function connect_login_db($db_add,$conn_name,$conn_pwd,$db_name){
		$conn=mysql_connect($db_add,$conn_name,$conn_pwd);
		mysql_query("set names utf8");
		if(!$conn){
			die("数据库连接失败！");
		}else{
			mysql_select_db($db_name,$conn);

		}
	}


	function get_login_session($login_session_value){
		if(isset($_SESSION[$login_session_value]) && $_SESSION[$login_session_value] != ''){
			echo "true";
		}else{
			echo "false";
		}
	}
}//end LOGIN_INFO class


?>